package com.example.administrator.newfragmentation.fragmentMain;

import android.content.Context;

import com.example.administrator.newfragmentation.fragment.zhihu.first.ZhiHuFirstFragment;

/**
 * Created by Administrator on 2017/4/10 0010.
 */

public abstract class BaseZhiHuFragment extends BaseFragment {

    protected  OnBackToFirstListener listener;

    public interface OnBackToFirstListener {
        void onBackToFirstFragment();
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnBackToFirstListener) {
            listener = (OnBackToFirstListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnBackToFirstListener");
        }
    }

    @Override
    public boolean onBackPressedSupport() {
        if(getChildFragmentManager().getBackStackEntryCount() > 1){
            popChild();
        }else{
            if(this instanceof ZhiHuFirstFragment){
                _mActivity.finish();
            }else{
                listener.onBackToFirstFragment();
            }
        }
        return true;
    }

    @Override
    public void onDetach() {
        super.onDetach();
        listener = null;
    }

}
